<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title></title>
<#include "/jeecms_sys/head.html"/>
<script src="${base}/res/zclip/jquery.zclip.min.js" type="text/javascript"></script>
<script type="text/javascript">
function getTableForm() {
	return document.getElementById('tableForm');
}
function optDelete() {
	if(Pn.checkedCount('ids')<=0) {
		$.alert("<@s.m 'global.prompt'/>","<@s.m 'error.checkRecord'/>");
		return;
	}
	$.confirm(doDelete,"<@s.m 'global.confirm'/>","<@s.m 'global.confirm.delete'/>");
}
function doDelete(){
	var f = getTableForm();
	f.action="o_delete.do";
	f.submit();
}
$(function() {
	$("#editForm").validate();
	$('#copy').zclip({
		path:'${base}/res/zclip/ZeroClipboard.swf',
		copy:function(){
			var checkCount=Pn.checkedCount('ids');
			if(checkCount<=0) {
				$.alert("<@s.m 'global.prompt'/>","<@s.m 'error.checkRecord'/>");
				return;
			}else if(checkCount>1) {
				$.alert("<@s.m 'global.prompt'/>","<@s.m 'error.checkOne'/>");
				return;
			}else{
				var id=$("input[type=checkbox][name='ids']:checked").val();
				return $('#codeText_'+id).val();
			}
		},
		afterCopy:function(){
			$.alert("<@s.m 'global.prompt'/>","<@s.m 'global.copy.success'/>");
		}
	});
	$("#codeDialog").dialog({
		autoOpen: false,
		height: 300,
		width: 600,
		modal: true,
		buttons: {
			"<@s.m code='global.closeWindow'/>": function() {
				$( "#codeDialog" ).dialog("close");
			}
		}
	});
	$("#editDialog").dialog({
		autoOpen: false,
		height: 300,
		width: 600,
		modal: true,
		buttons: {
			"<@s.m code='global.submit'/>": function() {
			$("#editForm").submit();
				var errorlength=$(".error").length;
				if(errorlength<0){
					$( this ).dialog( "close" );
				}
			},
			"<@s.m code='global.reset'/>": function() {
				$("#editForm")[0].reset();
			}
		}
	});
	$("a[id^='view_']").click(function() {
		var codeId="codeText_"+$(this).attr("id").split("view_")[1];
		$("#codeText").val($("#"+codeId).val());
		$( "#codeDialog" ).dialog("open");
	});
	$("a[id^='edit_']").click(function() {
		getData($(this).attr("id").split("edit_")[1]);//获取json数据  
		$( "#editDialog" ).dialog("open");
	});
});
function getData(id){
    $.getJSON("v_ajax_edit.do",{id:id},function(data){  
        $("#name").val(data.name); 
        $("#description").val(data.description); 
        $("#codeEditText").val(data.code); 
        $("#id").val(data.id);
  });  
}
</script>
</head>
<body>
<div class="box-positon">
	<div class="rpos"><@s.m "global.position"/>: <@s.m "directive.function"/> - <@s.m "global.list"/></div>
	<form class="ropt">
		<input class="add" type="submit" value="<@s.m "global.add"/>" onclick="this.form.action='v_add.do';"/>
	</form>
	<div class="clear"></div>
</div>
<div class="body-box">
<form id="tableForm" method="post">
<input type="hidden" name="pageNo" value="${pageNo!}"/>
<@p.table value=pagination;tpl,i,has_next><#rt/>
	<@p.column title="<input type='checkbox' onclick='Pn.checkbox(\"ids\",this.checked)'/>" width="25" align="center">
		<input type='checkbox' name='ids' value='${tpl.id}' onclick="Pn.selectCheckBox('${tpl.id}',this.checked)"/><#t/>
	</@p.column><#t/>
	<@p.column code="directive.name" align="center">${tpl.name}</@p.column><#t/>
	<@p.column code="directive.code" align="center">
		<textarea style="width: 400px;height:30px" id="codeText_${tpl.id}">${tpl.code!}</textarea>
	</@p.column><#t/>
	<@p.column code="directive.user" align="center">${tpl.user.username}</@p.column><#t/>
	<@p.column code="global.operate" align="center">
		<a href="#" class="pn-opt" id="view_${tpl.id}"><@s.m "directive.code.view"/></a> | <#rt/>
		<a href="#" class="pn-opt" id="edit_${tpl.id}"><@s.m "global.edit"/></a> | <#rt/> 
		<a href="o_delete.do?ids=${tpl.id}&pageNo=${pageNo!}" onclick="if(!$.confirmToUrl(this.href)) {return false;}" class="pn-opt"><@s.m "global.delete"/></a> <#rt/>
	</@p.column><#t/>
</@p.table>
<div style="background:url(${base}/res/common/img/theme/boxTitleBG.jpg) repeat-x; height:20px; overflow:hidden;">
<input id="copy" class="fzbq-button" type="button" value="<@s.m "directive.code.copy"/>" / style="float:left; border-right:1px solid #ffffff;">
<input class="del-button" type="button" value="<@s.m "global.delete"/>" onclick="optDelete();"/ style="float:left; border-right:1px solid #ffffff;">
</div>
</form>
</div>
<div id="codeDialog" title="<@s.m 'directive.function'/> - <@s.m 'directive.code.view'/>">
	<textarea style="width: 550px;height:300px" id="codeText">
	</textarea>
</div>
<div id="editDialog" title="<@s.m 'directive.function'/> - <@s.m 'global.edit'/>">
	<@p.form id="editForm" action="o_update.do" labelWidth="20">
	<@p.text width="100" colspan="2" label="directive.name" id="name" name="name" required="true" class="required" maxlength="100"/><@p.tr/>
	<@p.td width="100" colspan="2" label="directive.description">
	<textarea style="width: 500px;height:50px" id="description" name="description">
	</textarea>
	</@p.td><@p.tr/>
	<@p.td width="100" colspan="2" label="directive.code">
	<textarea style="width: 500px;height:250px" id="codeEditText" name="code">
	</textarea>
	<@p.hidden name="id" id="id"/>
	</@p.td>
	<@p.tr/>
	</@p.form>
</div>
<input type="hidden" id="codeHidden"/>
<#include "/common/alert_message.html"/>
</body>
</html>